# -*- coding: utf-8 -*-
from django import forms
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from main.models import UserProfile, PracticeReservation, FriendLink

class PracticeReservationAdmin(admin.ModelAdmin):
    list_display=('date', 'name',  'sex', 'birthday', 'parent_name', 'parent_relation', 'company','phone', 'address', 'zipcode','email','nursery','center', 'classes')
#    list_filter=('processed', 'classes', 'center')
class FriendLinkAdmin(admin.ModelAdmin):
    list_display=('date', 'link', 'display_name', 'is_display',)

class UserProfileInline(admin.StackedInline):
    model = UserProfile

class UserAdmin(UserAdmin):
    inlines = [
        UserProfileInline,
    ]

    def profile_name(self):
        return self.userprofile.name
    profile_name.short_description = '孩子姓名'

    def profile_date(self):
        return self.userprofile.date
    profile_date.short_description = '注册时间'

    def profile_sex(self):
        return self.userprofile.sex
    profile_sex.short_description = '孩子性别'

    def profile_parent_name(self):
        return self.userprofile.parent_name
    profile_parent_name.short_description = '家长姓名'

    def profile_parent_relation(self):
        return self.userprofile.parent_relation
    profile_parent_relation.short_description = '与孩子关系'

    def profile_phone(self):
        return self.userprofile.phone
    profile_phone.short_description = '手机号码'

    def profile_email(self):
        return self.userprofile.email
    profile_email.short_description = '电子邮件'

    list_display = ('username', profile_date, profile_name, profile_sex, profile_parent_name, profile_parent_relation, profile_phone, profile_email)
    search_fields = ('username', 'userprofile__name', 'userprofile__phone')

admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(PracticeReservation, PracticeReservationAdmin)
admin.site.register(FriendLink, FriendLinkAdmin)

